package cn.tth.test.game.collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class MyList<E> extends ArrayList<E> {

    public MyList(Collection<? extends E> c) {
        super(c);
    }

    public MyList() {
        super();
    }

    @Override
    public String toString() {
        Iterator<E> it = iterator();
        if (! it.hasNext())
            return "[]";

        StringBuilder sb = new StringBuilder();
        sb.append('[');
        for (int i = 0;;i++) {
            E e = it.next();
            sb.append(i).append("：").append(e == this ? "(this Collection)" : e);
            if (! it.hasNext())
                return sb.append(']').toString();
            sb.append('、').append(' ');
        }
    }
}
